package com.xiuxian.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiuxian.mapper.UserMapper;
import com.xiuxian.mapper.VideoMapper;
import com.xiuxian.model.Video;
import com.xiuxian.model.dto.VideoDTO;
import com.xiuxian.service.VideoService;
import com.xiuxian.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class VideoServiceImpl implements VideoService {

    private static SqlSession  sqlSession  = null;
    @Override
    public PageInfo<Video> getBytitle(String title, Integer pageNum, Integer pageSize) {


        PageInfo<Video>  pageInfo = null;
        try {
            //1.连接数据库
            sqlSession = MybatisUtils.getSqlSession();
            VideoMapper mapper = sqlSession.getMapper(VideoMapper.class);


            //2.设置分页
            PageHelper.startPage(pageNum,pageSize);

            List<Video> list = mapper.findbytitle(title);

            pageInfo = new PageInfo<>(list);

        }catch (Exception e){
            e.printStackTrace();
        }
        return pageInfo;
    }
}

